package odgs.message.client;

import java.util.List;
import java.util.Map;

import odgs.Connection;
import odgs.Directory;
import odgs.Explorer;
import odgs.ExplorerNode;
import odgs.LoginedGridNode;
import odgs.GridState;
import odgs.message.Message;
import odgs.message.MessageHandler;
import odgs.message.MessageProcessor;

public class LoginResponseHandler implements MessageHandler
{
	public void execute(MessageProcessor processor, Message msg, Connection con)
	{
		if(msg.getResult() < 0)
		{
			processor.getDataManager().error(msg.getResult());
		}
		else
		{
			GridState state = (GridState) msg.get("state");
			List<ExplorerNode> data = (List<ExplorerNode>) msg.get("explorer");
			Explorer explorer = new Explorer(new Directory("/",""));
			for (ExplorerNode node : data)
			{
				explorer.add(node);
			}
			
			processor.getDataManager().logined(explorer, state);
		}
	}
}
